package com.tczs.client;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.CharsetUtil;

@ChannelHandler.Sharable
public class ClientChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ByteBuf buf = Unpooled.copiedBuffer("3LKCJ", CharsetUtil.UTF_8);//自定义拆包字符
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new IdleStateHandler(20,5, 0));
        pipeline.addLast(new DelimiterBasedFrameDecoder(1024*50,true,buf));
        pipeline.addLast(new ClientTimeOutHandler());
        pipeline.addLast(new ClientHandler());
        pipeline.addLast(new StringEncoder());
    }

}
